import uuid

from sqlalchemy import (
    Column,
    String,
    Integer,
    DateTime,
    PrimaryKeyConstraint,
    Boolean,
    text, Index
)
from internal.extension.extension_db import db
from internal.model.tour_guide import TourGuide


class TravelAgency(db.Model):
    """旅行社表"""
    __tablename__ = 'travel_agency'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='travel_agency_id_pkey'),
    )
    id = Column(String(36), nullable=False, default=lambda: str(uuid.uuid4()))
    deleted = Column(Boolean, nullable=False, default=False)
    bash_id = Column(String(36), nullable=False) #批次id
    travel_agency_name = Column(String(20), nullable=False) #旅行社名称
    get_number = Column(Integer, nullable=True) #选择的安检口
    grounp_id = Column(String(36), nullable=False,default="") #分组编号
    order_no = Column(String(50), nullable=True) #预约编号
    playDate = Column(String(100), nullable=False) #预约日期
    start_time = Column(String(50), nullable=True)
    end_time = Column(String(50), nullable=True)
    updated_at = Column(
        DateTime,
        nullable=False,
        server_default=text("CURRENT_TIMESTAMP(0)"),
        server_onupdate=text("CURRENT_TIMESTAMP(0)"),
    )
    created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP(0)"))
    @property
    def get_member_data(self):
        from internal.model import Member

        return db.session.query(Member).filter(Member.travel_agency_id == self.id).one_or_none()
    @property
    def get_tour_guide(self)->TourGuide:
        return db.session.query(TourGuide).get(TourGuide.bash_id == self.bash_id).one_or_none()

